package com.ruoyi.web.controller.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.IStudyReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.Example;
import io.swagger.annotations.ExampleProperty;

@Api(tags = "学习报告管理")
@RestController
@RequestMapping("/api/v1/study")
public class ApiStudyReportController {
    @Autowired
    private IStudyReportService studyReportService;

    @ApiOperation(
        value = "获取学习报告",
        notes = "获取用户的学习进度报告，包含学习时长、完成单词数等统计信息",
        response = AjaxResult.class
    )
    @ApiImplicitParams({
        @ApiImplicitParam(
            name = "Authorization",
            value = "Bearer Token认证信息",
            required = true,
            dataType = "String",
            paramType = "header",
            example = "Bearer eyJhbGciOiJIUzUxMiJ9.xxx"
        )
    })
    @ApiResponses({
        @ApiResponse(
            code = 200,
            message = "操作成功",
            response = AjaxResult.class,
            examples = @Example(value = {
                @ExampleProperty(
                    mediaType = "application/json",
                    value = "{\"code\":200,\"msg\":\"操作成功\",\"data\":{\"totalStudyTime\":3600,\"totalWords\":500,\"completedWords\":300,\"accuracy\":0.85,\"lastStudyTime\":\"2024-01-20 15:30:00\"}}"
                )
            })
        ),
        @ApiResponse(
            code = 401,
            message = "未登录或Token已过期"
        ),
        @ApiResponse(
            code = 500,
            message = "系统内部错误"
        )
    })
    @GetMapping("/report")
    public AjaxResult report(
            @ApiParam(value = "每页记录数", required = false) @RequestParam(required = false) Integer pageSize,
            @ApiParam(value = "页码", required = false) @RequestParam(required = false) Integer pageIndex) {
    	Long studentId = SecurityUtils.getLoginStudentId();
        return AjaxResult.success(studyReportService.getStudyReport(studentId, pageSize, pageIndex));
    }
}